﻿using System;
using System.Collections;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Linq;
namespace Framework.UnitTest
{
    [TestClass]
    public class ThreadTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void TestMethod1()
        {
            Stopwatch sw1 = Stopwatch.StartNew();

            int y = 0;
            var item = Enumerable.Range(0, 10000).Each(i =>
                                                       Task.Factory.StartNew(() =>
                                                           {

                                                               y = y + 1;

                                                           }
                                                           )
                ).ToArray();

            Task.WaitAll(item);

            sw1.Stop();
            TestContext.WriteLine("y=" + y);
            TestContext.WriteLine("Task耗时" + sw1.ElapsedMilliseconds);
        }
    }
}
